home *** CD-ROM | disk | FTP | other *** search
- #include "all.h"
- #include "regtabint.h"
-
- main()
- {
- int t, i, j, k, ii, jj, kk, tBoolean, itop, ileft;
- Handle TEScrH;
- int lastEvCoChar, lastEvPrChar;
- long nBytes, offsetTE, lengthTE;
- float x, y;
- char c;
- GrafPtr savePort;
- void ScrollUp(), ScrollDown();
- void TScrollUp(), TScrollDown();
- Rect tRect, tRect2;
- char s[cmdWordLen], *gaddr;
-
- infinity = 0.0;
- minfinity = -1.0 / infinity;
- infinity = 1.0/infinity;
- nCoeffs = 0;
- for( i=0; i<33; i++ ) coeffs[i]=0.0;
-
- lastEvCoChar = FALSE;
- lastEvPrChar = FALSE;
-
- macVars.numVars = 0;
-
- InitGraf(&thePort); /* sets global variables thePort to nil and screenBits to Mac screen */
- InitFonts();
- FlushEvents(everyEvent,0);
- InitWindows();
-
- /* set up menus */
- InitMenus();
- myMenu[apMenu] = GetMenu(apMenuRes);
- AddResMenu(myMenu[apMenu],'DRVR'); /* desk accesories */
- myMenu[fiMenu] = GetMenu(fiMenuRes);
- myMenu[edMenu] = GetMenu(edMenuRes);
- myMenu[wiMenu] = GetMenu(wiMenuRes);
- myMenu[abMenu] = GetMenu(abMenuRes);
- for ( i = 0; i < lastMenu; i++ )
- InsertMenu(myMenu[i],0);
- DrawMenuBar();
-
- TEInit();
- InitDialogs(0L);
- InitAllPacks();
- InitPack(stdFile);
- SetCursor(&arrow);
- SetRect(&dragRect, 0, 40, 700, 344);
- SetRect(&growRect, 50, 50, windowWidth, windowHeight);
- SetRect(&abortRect, 180, 0, 220, 20 );
- SetRect(&wayOffScreen,1000,1000,1100,1100);
- doneFlag = FALSE;
- pendingFlag = FALSE;
- InitCursor();
-
- /* set up graphics window */
- grPortPtr = &grPort;
- OpenPort( grPortPtr );
- SetPort( grPortPtr );
- grMap.rowBytes = windowWidth / 8 + 1;
- if( (grMap.rowBytes & 1) != 0 ) grMap.rowBytes++; /* make sure its even */
- SetRect( &(grMap.bounds), 0, 0, windowWidth, windowHeight );
- nBytes = grMap.rowBytes * (grMap.bounds.bottom - grMap.bounds.top);
- grMap.baseAddr = NewPtr(nBytes);
- grPort.portBits = grMap;
- grPort.portRect = grMap.bounds;
- SetPort( grPortPtr );
- gaddr = (char*) grMap.baseAddr;
- for( i=0; i<nBytes; i++ ) {
- *gaddr = '\0';
- gaddr++;
- } /*end for*/
- EraseRect( &(grPort.portRect) );
- FrameRect( &(grPort.portRect) );
-
- SetPort( thePort );
-
- /* define windows */
-
- theWindow[edWindow] = GetNewWindow( edWndRes, &wRecord[0], -1L );
- theWindow[prWindow] = GetNewWindow( prWndRes, &wRecord[1], -1L );
- theWindow[grWindow] = GetNewWindow( grWndRes, &wRecord[2], -1L );
- theWindow[coWindow] = GetNewWindow( coWndRes, &wRecord[3], -1L );
- for( i=0; i<lastWindow; i++ ) {
- theWindow[i]->txFont = 2;
- vScroll[i] = GetNewControl( 256, theWindow[i]);
- hScroll[i] = GetNewControl( 257, theWindow[i]);
- theOrigin[i].h = 0;
- theOrigin[i].v = 0;
- topPixel[i] = 1;
- leftPixel[i] = 1;
- } /* end for */
-
- /* command window */
- SetPort(theWindow[coWindow]);
- SetRect(&tRect, 4, 4, 720, 364);
- tRect2 = theWindow[coWindow]->portRect;
- IndentRect( &tRect2 );
- coText = TENew( &tRect, &tRect2 );
- (*coText)->crOnly = -1;
- TEInsert("Scientist\'s Helper, Version 2.7, by William Menke\r",50L,coText);
- TEInsert("Caveat Emptor\r",14L,coText);
- TEInsert("\r",1L,coText);
-
- /* procedure window */
- SetPort(theWindow[prWindow]);
- SetRect(&tRect, 4, 4, 720, 364);
- tRect2 = theWindow[prWindow]->portRect;
- IndentRect( &tRect2 );
- prText = TENew( &tRect, &tRect2 );
- (*prText)->crOnly = -1;
- TEInsert("label sample\r",13L,prText);
- TEInsert("prompt \'hi there\'\r",18L,prText);
- TEInsert("return\r",7L,prText);
-
- /*table edit window */
- SetPort(theWindow[edWindow]);
- edText = TENew( &wayOffScreen, &wayOffScreen );
- (*edText)->crOnly = -1;
- (*edText)->txSize = 10;
- (*edText)->txFont = geneva;
- TextFont(geneva);
- TextSize(10);
- for( i=0; i<4; i++ ) {
- SetRect( &(tabEd.name[i]), ((i+1)*100)+1, 1, (i+2)*100, 15 );
- }
- for( i=0; i<19; i++ ) {
- SetRect( &(tabEd.row[i]), 1, ((i+1)*15)+1, 100, (i+2)*15 );
- }
- for( i=0; i<19; i++ ) {
- for( j=0; j<4; j++ ) {
- SetRect( &(tabEd.entry[i][j]), ((j+1)*100)+1, ((i+1)*15)+1, (j+2)*100, (i+2)*15 );
- } }
- tabEd.activeEntry = FALSE;
- tabEd.activeName = FALSE;
-
- LoadSg1(); /*force load of all segments of program*/
- LoadSg2();
- LoadSg3();
-
- InitTable(); /*initialize table*/
- WritePhrase("> ");
-
- /* initialize procedure info */
- mem.active = FALSE;
- mem.stackPtr = -1;
- mem.numLabels = 0;
- loops.numLoops = 0;
-
- graph.xMin = 0.0;
- graph.xMax = 1.0;
- graph.yMin = 0.0;
- graph.yMax = 1.0;
- Graph2Vars();
-
- currentWindow = -1;
- scrapIndex = -1;
- SelectWindow(theWindow[coWindow]);
- ZeroScrap();
- setjmp(envbuf);
-
-
- do {
-
- SystemTask();
-
- if( scrapIndex != (InfoScrap())->scrapCount ) {
- scrapIndex = (InfoScrap())->scrapCount;
- lengthTE = GetScrap( TEScrapHndl(), 'TEXT', &offsetTE );
- if (lengthTE>0) (*((short *) 0x0AB0)) = lengthTE;
- }
-
- GetNextEvent(everyEvent,&myEvent);
-
- while ( (*coText)->teLength > maxCoChars ) { /*nips top off of command window if too big*/
- TECalText(coText);
- i = (*coText)->selStart;
- j = (*coText)->selEnd;
- ii = (*coText)->lineStarts[0];
- jj = (*coText)->lineStarts[1];
- t = currentWindow;
- GetPort( &oldPort );
- SetPort( theWindow[coWindow] );
- currentWindow = coWindow;
- whichWindow = theWindow[currentWindow];
- TESetSelect( (long)ii, (long)jj, coText );
- TEDelete( coText );
- kk = jj - ii;
- TESetSelect( (long)(i-kk), (long)(j-kk), coText );
- IfOutScroll(coText);
- SetPort( oldPort );
- currentWindow=t;
- whichWindow = theWindow[currentWindow];
- }
-
- if (mem.active && (!pendingFlag) && (myEvent.what==nullEvent) ) { /*get command line from procedure memory*/
- mem.stack[ mem.stackPtr ] ++;
- if (mem.stack[mem.stackPtr] >= (*prText)->nLines ) {
- ErrMsg( "attempt to read past end of procedure" );
- } /*end if error*/
- HLock((*prText)->hText);
- j=(*prText)->lineStarts[mem.stack[mem.stackPtr]];
- k=(*prText)->teLength;
- ExtractLine( *((*prText)->hText), j, k, s );
- HUnlock((*prText)->hText);
- CmdFromWnd(s,FALSE);
- } /*end if procedure is running*/
-
- TEIdle(coText);
- TEIdle(prText);
- TEIdle(edText);
-
- switch(myEvent.what) {
- case activateEvt:
- lastEvCoChar=FALSE;
- lastEvPrChar=FALSE;
- /* activate events return a window pointer as their message */
- /* find the window that corresponds to this pointer (if any) */
-
- /*cant activate procedure or edit window if procedure is running*/
- whichWindow = (WindowPtr)myEvent.message;
- GetWndNumber(whichWindow);
- if( currentWindow < 0 ) /* window not found */
- break;
- SetPort(theWindow[currentWindow]);
- if (myEvent.modifiers&1) {
- ShowControl(vScroll[currentWindow]);
- ShowControl(hScroll[currentWindow]);
- DrawControls(theWindow[currentWindow]);
- DrawGrowIcon(theWindow[currentWindow]);
- if( currentWindow == coWindow ) {
- TEActivate( coText );
- }
- else if( currentWindow == prWindow ) {
- TEActivate( prText );
- }
- else if( (currentWindow==edWindow) &&
- (tabEd.activeName||tabEd.activeEntry) ) {
- TEActivate( edText );
- }
- }
- else {
- if( currentWindow == coWindow ) {
- TEDeactivate( coText );
- }
- else if( currentWindow == prWindow ) {
- TEDeactivate( prText );
- }
- else if( currentWindow == edWindow ) {
- TEDeactivate( edText );
- ClipRect( &(whichWindow->portRect) );
- }
- HideControl(vScroll[currentWindow]);
- HideControl(hScroll[currentWindow]);
- }
- break;
-
- case updateEvt :
- lastEvCoChar=FALSE;
- lastEvPrChar=FALSE;
-
- GetPort(&savePort);
- whichWindow = (WindowPtr)myEvent.message;
- GetWndNumber(whichWindow);
- if( currentWindow < 0 ) /* window not found */
- break;
- SetPort(theWindow[currentWindow]);
- BeginUpdate(theWindow[currentWindow]);
- EraseRect(&theWindow[currentWindow]->portRect);
- DrawWindow();
- EndUpdate(theWindow[currentWindow]);
- SetPort(savePort);
- break;
-
- case mouseDown :
- lastEvCoChar=FALSE;
- lastEvPrChar=FALSE;
-
- /* code returns what type of window */
- code = FindWindow(pass(myEvent.where), &whichWindow);
- GetWndNumber(whichWindow);
-
- /* determine if this window is up front */
- if ( whichWindow == FrontWindow() )
- frontFlag = TRUE;
- else
- frontFlag = FALSE;
-
- switch(code) {
- case inMenuBar :
- DoCommand(MenuSelect(pass(myEvent.where)));
- break;
- case inSysWindow :
- SystemClick(&myEvent,whichWindow);
- break;
- case inDrag :
- if( frontFlag ) {
- DragWindow(whichWindow,pass(myEvent.where),
- &dragRect);
- }
- else {
- if( !( (mem.active||pendingFlag) &&
- ( (currentWindow==prWindow) ||
- (currentWindow==edWindow) ) ) ) {
- SelectWindow(whichWindow);
- }
- }
- break;
- case inGrow :
- if (frontFlag) {
- GrowWnd(whichWindow);
- }
- else {
- if( !( (mem.active||pendingFlag) &&
- ( (currentWindow==prWindow) ||
- (currentWindow==edWindow) ) ) ) {
- SelectWindow(whichWindow);
- }
- }
- break;
- case inContent :
- if (frontFlag && (currentWindow==coWindow)) {
- GlobalToLocal(&myEvent.where);
- MyControl = FindControl(pass(myEvent.where),
- whichWindow,&whichControl);
- switch(MyControl) {
- case inUpButton :
- TrackControl(whichControl,pass(myEvent.where),
- TScrollUp);
- break;
- case inDownButton :
- TrackControl(whichControl,pass(myEvent.where),
- TScrollDown);
- break;
- case inPageUp :
- TPageScroll(MyControl,-6400);
- break;
- case inPageDown :
- TPageScroll(MyControl,6400);
- break;
- case inThumb :
- t = TrackControl(whichControl,pass(myEvent.where),
- 0L);
- ScrollBits();
- break;
- default:
- if( (myEvent.modifiers&shiftKey) == 1 )
- tBoolean = TRUE;
- else
- tBoolean = FALSE;
- TEClick(pass(myEvent.where),tBoolean,coText);
- } /*end switch MyControl*/
- } /*end if coWindow*/
- else if (frontFlag && (currentWindow==grWindow)) {
- GlobalToLocal(&myEvent.where);
- MyControl = FindControl(pass(myEvent.where),
- whichWindow,&whichControl);
- switch(MyControl) {
- case inUpButton :
- TrackControl(whichControl,pass(myEvent.where),
- ScrollUp);
- break;
- case inDownButton :
- TrackControl(whichControl,pass(myEvent.where),
- ScrollDown);
- break;
- case inPageUp :
- PageScroll(MyControl,-6400);
- break;
- case inPageDown :
- PageScroll(MyControl,6400);
- break;
- case inThumb :
- t = TrackControl(whichControl,pass(myEvent.where),
- 0L);
- ScrollBits();
- break;
- default:
- i = (myEvent.where.h+theOrigin[grWindow].h);
- j = (myEvent.where.v+theOrigin[grWindow].v);
- InvGraphScale( i, j, &x, &y );
- RToS( x, s );
- currentWindow=coWindow;
- whichWindow=theWindow[coWindow];
- SetPort(theWindow[currentWindow]);
- if(!SetVar("xpos",s)){
- ErrMsg("couldnt set xpos variable");
- }
- WritePhrase(s);
- WritePhrase(" ");
- RToS( y, s );
- if(!SetVar("ypos",s)){
- ErrMsg("couldnt set ypos variable");
- }
- WriteLine(s);
- currentWindow=grWindow;
- whichWindow=theWindow[grWindow];
- SetPort(theWindow[currentWindow]);
- if(pendingFlag) {
- currentWindow=grWindow;
- whichWindow=theWindow[coWindow];
- SelectWindow(theWindow[coWindow]);
- PostEvent(keyDown,(long)'\r');
- longjmp(envbuf,-1);
- }
- } /*end switch MyControl */
- } /*end if grWindow*/
- else if (frontFlag && (currentWindow==prWindow)) {
- GlobalToLocal(&myEvent.where);
- MyControl = FindControl(pass(myEvent.where),
- whichWindow,&whichControl);
- switch(MyControl) {
- case inUpButton :
- TrackControl(whichControl,pass(myEvent.where),
- TScrollUp);
- break;
- case inDownButton :
- TrackControl(whichControl,pass(myEvent.where),
- TScrollDown);
- break;
- case inPageUp :
- TPageScroll(MyControl,-6400);
- break;
- case inPageDown :
- TPageScroll(MyControl,6400);
- break;
- case inThumb :
- t = TrackControl(whichControl,pass(myEvent.where),
- 0L);
- ScrollBits();
- break;
- default:
- if( (myEvent.modifiers&shiftKey) == 1 )
- tBoolean = TRUE;
- else
- tBoolean = FALSE;
- TEClick(pass(myEvent.where),tBoolean,prText);
- } /*end switch MyControl*/
- }/*end if prWindow*/
- else if (frontFlag && (currentWindow==edWindow)) {
- GlobalToLocal(&myEvent.where);
- MyControl = FindControl(pass(myEvent.where),
- whichWindow,&whichControl);
- switch(MyControl) {
- case inUpButton :
- TrackControl(whichControl,pass(myEvent.where),
- TScrollUp);
- break;
- case inDownButton :
- TrackControl(whichControl,pass(myEvent.where),
- TScrollDown);
- break;
- case inPageUp :
- TPageScroll(MyControl,-6400);
- break;
- case inPageDown :
- TPageScroll(MyControl,6400);
- break;
- case inThumb :
- t = TrackControl(whichControl,pass(myEvent.where),
- 0L);
- ScrollBits();
- break;
- default:
- ileft = (GetCtlValue(hScroll[edWindow])/1024)+1;
- itop = (GetCtlValue(vScroll[edWindow])/8)+1;
- ResizePRect();
- ClipRect( &pRect );
- if( tabEd.activeName || tabEd.activeEntry ) {
- /*get text from edit record and delete the text*/
- HLock((*edText)->hText);
- i=(*edText)->teLength;
- ExtractLine( *((*edText)->hText), 0, (i-1), s );
- HUnlock((*edText)->hText);
- TEDeactivate(edText);
- TESetSelect( 0L, (long)i, edText );
- TEDelete(edText);
- }
- if( tabEd.activeName ) {
- if( GoodCol(tabEd.c)==0 ) {
- strcpy( table.header.colName[tabEd.c-1], s );
- }
- else {
- SysBeep(5);
- strcpy( s, " ");
- }
- EraseRect( &(tabEd.name[tabEd.c-ileft]) );
- MoveTo( (tabEd.name[tabEd.c-ileft]).left+1,
- (tabEd.name[tabEd.c-ileft]).bottom-2 );
- DrawText( s, 0, strlen(s) );
- }
- else if( tabEd.activeEntry ) {
- if( (GoodCol(tabEd.c)==0) && (GoodRow(tabEd.r)==0) ) {
- if( table.header.interpolated && (tabEd.c==1) ) {
- SysBeep(5);
- GetTable( tabEd.r, 1, &x );
- RToS(x,s);
- }
- else {
- SToR( s, &x, TRUE );
- RToS( x, s, TRUE );
- SetTable( tabEd.r, tabEd.c, x, FALSE );
- }
- }
- else {
- SysBeep(5);
- strcpy(s,"");
- }
- EraseRect( &(tabEd.entry[tabEd.r-itop][tabEd.c-ileft]) );
- MoveTo( (tabEd.entry[tabEd.r-itop][tabEd.c-ileft]).left+1,
- (tabEd.entry[tabEd.r-itop][tabEd.c-ileft]).bottom-2 );
- DrawText( s, 0, strlen(s) );
- }
- tabEd.activeName=FALSE;
- tabEd.activeEntry=FALSE;
- for( j=0; j<4; j++ ) {
- if( PtInRect( pass(myEvent.where), &(tabEd.name[j]) ) ){
- tabEd.c=ileft+j;
- tabEd.activeName=TRUE;
- jj=j;
- break;
- } /*end if*/
- } /*end for*/
- for( i=0; (i<19)&&(!tabEd.activeName);i++ ) {
- for( j=0; j<4; j++ ) {
- if( PtInRect( pass(myEvent.where), &(tabEd.entry[i][j]) ) ) {
- tabEd.r=itop+i;
- tabEd.c=ileft+j;
- tabEd.activeEntry=TRUE;
- ii=i;
- jj=j;
- break;
- } /*end if*/
- } } /*end fors*/
- if( tabEd.activeName ) {
- if( GoodCol(tabEd.c)!=0 ) {
- SysBeep(5);
- tabEd.activeName=FALSE;
- break;
- }
- (*edText)->destRect=tabEd.name[jj];
- ResizeEdBox();
- TESetSelect( 0L, (long)(*edText)->teLength, edText );
- TEDelete(edText);
- TEInsert( table.header.colName[tabEd.c-1],
- (long)strlen(table.header.colName[tabEd.c-1]), edText );
- TESetSelect( 0L, (long)((*edText)->teLength), edText );
- TEActivate( edText );
- TEUpdate(&((*edText)->viewRect),edText);
- }
- else if( tabEd.activeEntry ) {
- if( (GoodRow(tabEd.r)!=0) || (GoodCol(tabEd.c)!=0)
- || ((tabEd.c==1)&&table.header.interpolated) ) {
- SysBeep(5);
- tabEd.activeEntry=FALSE;
- break;
- }
- (*edText)->destRect=tabEd.entry[ii][jj];
- ResizeEdBox();
- GetTable( tabEd.r, tabEd.c, &x );
- RToS( x, s );
- TESetSelect( 0L, (long)(*edText)->teLength, edText );
- TEDelete(edText);
- TEInsert( s, (long)strlen(s), edText );
- TESetSelect( 0L, (long)((*edText)->teLength), edText );
- TEActivate( edText );
- TEUpdate(&((*edText)->viewRect),edText);
- }
- else {
- SysBeep(5);
- }
- } /*end switch MyControl*/
- }/*end if edWindow*/
- else {
- if( !( (mem.active||pendingFlag) &&
- ( (currentWindow==prWindow) ||
- (currentWindow==edWindow) ) ) ) {
- SelectWindow(whichWindow);
- }
- }
- break;
- } /* end switch code */
- break;
-
- case keyDown:
- case autoKey:
- if( mem.active && (!pendingFlag) ) {
- break;
- }
- c = (char) (myEvent.message & charCodeMask);
- whichWindow = FrontWindow();
- GetWndNumber(whichWindow);
- SetPort(whichWindow);
- if( ((myEvent.modifiers & cmdKey) != 0)
- && ((currentWindow==coWindow) || (currentWindow==prWindow)
- || (currentWindow==grWindow) || (currentWindow==edWindow) )
- ) {
- DoCommand( MenuKey(c) );
- } /*end if cmdkey down*/
- else if (currentWindow == coWindow) {
- if( c==(char)3 ) c='\r'; /*enter key is return*/
- TEKey( c, coText );
- if( (!lastEvCoChar) || (c=='\r') ) IfOutScroll( coText);
- if( (c=='\r') &&
- ((*coText)->selEnd >= ((*coText)->teLength-1)) ) {
- HLock((*coText)->hText);
- j=(*coText)->lineStarts[(*coText)->nLines-1];
- k=(*coText)->teLength-2;
- ExtractLine( *((*coText)->hText), j, k, s );
- HUnlock((*coText)->hText);
- CmdFromWnd(s,TRUE);
- } /*end if return*/
- lastEvCoChar=TRUE;
- lastEvPrChar=FALSE;
- } /* end if coWindow and frontwindow */
- else if( (currentWindow==prWindow) && (!pendingFlag) ){
- if( c==(char)3 ) c='\r'; /*enter key is return*/
- TEKey( c, prText );
- if( (!lastEvPrChar) || (c=='\r') ) IfOutScroll( prText );
- lastEvCoChar=FALSE;
- lastEvPrChar=TRUE;
- } /*end if prWindow and frontwindow*/
- else if( currentWindow==grWindow) {
- lastEvCoChar=FALSE;
- lastEvPrChar=FALSE;
- SysBeep(5);
- }
- else if( (currentWindow==edWindow) && (tabEd.activeEntry||tabEd.activeName) ){
- lastEvCoChar=FALSE;
- lastEvPrChar=FALSE;
- ResizePRect();
- ClipRect( &pRect );
- if( c==(char)3 ) c='\r'; /*enter key is return*/
- TEKey( c, edText );
- if( c=='\r' ) {
- HLock((*edText)->hText);
- ExtractLine( *((*edText)->hText), 0, (*edText)->teLength-1, s );
- HUnlock((*edText)->hText);
- if( tabEd.activeName ) {
- strcpy( table.header.colName[tabEd.c-1], s );
- tabEd.activeName=FALSE;
- strcpy(s,"");
- }
- else if( tabEd.activeEntry ) {
- SToR( s, &x );
- SetTable( tabEd.r, tabEd.c, x, FALSE );
- if (GoodRow(tabEd.r+1)==0) {
- tabEd.r++;
- GetTable(tabEd.r,tabEd.c,&x);
- RToS( x, s );
- }
- else {
- tabEd.activeEntry=FALSE;
- strcpy(s,"");
- }
- SetCtlValue(vScroll[edWindow],GetCtlValue(vScroll[edWindow])+8);
- }
- ClipRect( &(whichWindow->portRect) );
- InvalRect(&(whichWindow->portRect));
- (*edText)->destRect = wayOffScreen;
- (*edText)->viewRect = wayOffScreen;
- TESetSelect( 0L, (long)(*edText)->teLength, edText );
- TEDelete(edText);
- TEInsert(s,(long)strlen(s),edText);
- TESetSelect( 0L, (long)(*edText)->teLength, edText );
- TEActivate(edText);
- } /*end if return*/
- } /* end if edWindow and frontwindow */
- break;
-
- } /* end switch what event */
- } while ( !(doneFlag=done()) ) ;
-
- TEScrH=TEScrapHndl();
- HLock(TEScrH);
- ZeroScrap();
- PutScrap( TEGetScrpLen(), 'TEXT', *TEScrH );
- HUnlock(TEScrH);
- scrapIndex = (InfoScrap())->scrapCount;
-
- ExitToShell();
- } /* end main */
-